package com.emser.unc.activitys.resources;

import android.text.Editable;
import android.text.TextWatcher;
import android.widget.Button;
import android.widget.EditText;

public class NewCustomerWatcher implements TextWatcher {

	Button acceptButton;
	EditText firstNameEditor;
	EditText lastNameEditor;
	EditText addressEditor;
	EditText phoneEditor;
	EditText city;
	EditText zipCode;

	public NewCustomerWatcher(EditText firstNameEditor,
			EditText lastNameEditor, EditText addressEditor,
			EditText phoneEditor, EditText city, EditText zipCode,
			Button acceptButton) {
		this.acceptButton = acceptButton;
		this.firstNameEditor = firstNameEditor;
		this.lastNameEditor = lastNameEditor;
		this.addressEditor = addressEditor;
		this.phoneEditor = phoneEditor;
		this.city = city;
		this.zipCode = zipCode;

		this.firstNameEditor.addTextChangedListener(this);
		this.lastNameEditor.addTextChangedListener(this);
		this.addressEditor.addTextChangedListener(this);
		this.phoneEditor.addTextChangedListener(this);
		this.city.addTextChangedListener(this);
		this.zipCode.addTextChangedListener(this);
		this.acceptButton.setEnabled(false);
	}

	@Override
	public void afterTextChanged(Editable arg0) {
		// TODO Auto-generated method stub

	}

	@Override
	public void beforeTextChanged(CharSequence arg0, int arg1, int arg2,
			int arg3) {
		// TODO Auto-generated method stub

	}

	@Override
	public void onTextChanged(CharSequence arg0, int arg1, int arg2, int arg3) {
		// TODO Auto-generated method stub
		startWatch();

	}

	public void startWatch() {
		Boolean containEmptyFields = addressEditor.getText().toString()
				.equals("")
				|| lastNameEditor.getText().toString().equals("")
				|| firstNameEditor.getText().toString().equals("")
				|| phoneEditor.getText().toString().equals("")
				|| city.getText().toString().equals("")
				|| zipCode.getText().toString().equals("");
		if (containEmptyFields) {
			this.acceptButton.setEnabled(false);
		} else {
			this.acceptButton.setEnabled(true);
		}
	}

}
